// pch.cpp: 与预编译标头对应的源文件

#include "pch.h"

int isprime;//全局变量

class Player//用于排行榜的玩家名及时间
{
public:
	string name;
	int time;
	Player(string name1, int time1)
	{
		name = name1;
		time = time1;
	}
	Player()
	{
		name = "\0";//初始化为零
		time = 0;
	}
	
private:
};







void swap(Player* a, Player* b) //交换函数，用于比较大小后交换
{
	Player temp = *a;
	*a = *b;
	*b = temp;
}

void movement(int* m0, int onclick, int location)//键盘事件
{
	
	
	switch (onclick) 
	{
	case 119:
	case 87:
		case 72:*m0 = location - 10;   break;//向上
	case 97:
	case 65:
		case 75:  if (location %10 == 1) location++;  *m0 = location - 1;  break;//向左
	case 115:
	case 83:
		case 80:*m0 = location + 10;  break;//向下
	case 100:
	case 68:
		case 77: if (location %10 == 0) location--;  *m0 = location + 1;  break;//向右
		default:break;
	}
}

void antimovement(int* m0, int onclick, int location)//反向移动
{
	switch (onclick)
	{
	case 119:
	case 87:
		case 72:*m0 = location + 10; break;
	case 97:
	case 65:
		case 75:*m0 = location + 1; break;
	case 115:
	case 83:
		case 80:*m0 = location - 10; break;
	case 100:
	case 68:
		case 77:*m0 = location - 1; break;
		default:break;
	}
}

void first() 
{
	
	cleardevice();
	
	int a[] = { 1,2,3,13,14,15,16,17,18,19,23,25,27,29,33,34,35,36,37,39
		,49,52,53,54,55,56,57,59,62,65,67,69,72,75,76,77,78,79,82,83,84,87,94 };//通道
	
	int num = sizeof(a) / sizeof(a[0]);//以字节相除判断数组大小
	
	int location = a[0];
	
	IMAGE yellow, white, pink,bomb;//定义图形类型
	
	loadimage(&white, "res/white.png");//将文件赋给定义名
	loadimage(&pink, "res/pink.png");
	loadimage(&yellow, "res/yellow.png");
	loadimage(&bomb, ("res/bomb.png"));
	
	while (1)
	{
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));//（x，y，文本）
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
				{                     
					drawImg(x, y, &yellow);//引用外部自定义函数去除图片阴影
				}
			}
		
		int cet = 0;
		
		for (int i = 1; i <= 100; i++)
		{
			
			int x = (i - 1) % 10;//x为横坐标
			
			int y = (i - 1) / 10;//y为纵坐标
			
			
			if (i == location)//粉块位置
			{
				cet++;
				drawImg(50 + x * 20, 50 + y * 20, &pink);
			}
			else if (i == a[cet])//通道加一跳过
			{
				cet++;
			}
			else
				drawImg(50 + x * 20, 50 + y * 20, &white);//隔墙
			
			
			if (i == 15 || i == 76 ) 
			{
				drawImg(50 + x * 20, 50 + y * 20, &bomb);//炸弹
			}
			
		}
		
		int onclick = _getch();//读入键盘事件
		
		cleardevice();//清屏
		
		int m = -1;
		
		int* m0 = &m;
		
		movement(m0, onclick, location);//引入此函数进行移动 
		
		
		for (int i = 0; i < num; i++) 
		{
			if (m == a[i]) 
			{
				location = m;
			}
		}
		
		/*炸弹结束游戏*/
		if (location == 15 || location == 76 ) 
		{
			gameover();
			
			
			
			break;
		}
		
		if (onclick == 27) 
		{
			pause();
			break;
		}
		
		if (location == a[num-1]) 
		{
			
			settlement();
			break;
		}
		
	}
	
}

void second()
{
	
	cleardevice();
	
	
	int a[] = { 1,11,12,13,16,17,23,24,25,26,27,35,37,38,39,45,46,47,49,52,
		53,54,55,59,64,65,66,67,68,69,72,73,74,75,84,85,86,87,88,98 };//通道
	int num = sizeof(a) / sizeof(a[0]);
	int location = a[0];
	
	IMAGE yellow, white, pink, bomb;
	
	loadimage(&white, "res/white.png");
	loadimage(&pink, "res/pink.png");
	loadimage(&yellow, "res/yellow.png");
	loadimage(&bomb, "res/bomb.png");
	
	while (1) 
	{
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		int cet = 0;
		
		for (int i = 1; i <= 100; i++)
		{
			
			int x = (i - 1) % 10;
			
			int y = (i - 1) / 10;
			
			if (i == location)
			{
				cet++;
				drawImg(50 + x * 20, 50 + y * 20, &pink);
			}
			else if (i == a[cet])
			{
				cet++;
			}
			else
				drawImg(50 + x * 20, 50 + y * 20, &white);
			
			
			if (i == 26 || i == 55 || i == 75) 
			{
				drawImg(50 + x * 20, 50 + y * 20, &bomb);           
			}
			
		}
		
		int onclick = _getch();
		
		cleardevice();
		
		int m = -1;
		
		int* m0 = &m;
		
		/*键盘事件*/
		
		antimovement(m0, onclick, location); 
		
		
		
		for (int i = 0; i < num; i++) 
		{
			if (m == a[i]) 
			{
				location = m;
			}
		}
		
		
		if (location == 26 || location == 55 || location == 75) //碰到炸弹
		{
			
			gameover();
			break;
		}
		
		if (onclick == 27) //ESC
		{
			pause();
			break;
		}
		
		if (location == a[num - 1]) 
		{
			
			settlement();//过关
			break;
		}
		
	}
	
}

void third()
{
	
	cleardevice();
	
	int a[] = { 1,2,12,13,14,22,32,33,34,42,44,52,53,54,62,72,74,82,83,84,94 };//通道
	int b[] = { 7,17,18,19,27,29,37,39,47,48,49,50,59,67,68,69,77,87,88,89,99 };//通道
	int num = sizeof(a) / sizeof(a[0]);
	int num1 = sizeof(b) / sizeof(b[0]);
	int location = a[0];
	int location1 = b[0];
	
	IMAGE yellow, white, pink, green, bomb, exit;
	
	loadimage(&white, _T("res/white.png"));//路障
	loadimage(&pink, _T("res/pink.png"));//人物
	loadimage(&yellow, _T("res/yellow.png"));//边框
	loadimage(&green, ("res/green.png"));//中间隔墙
	loadimage(&bomb, ("res/bomb.png"));//炸弹
	loadimage(&exit, ("res/exit.png"));//通道
	
	
	
	while (1)//打印地图
	{
		
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		int cet = 0,cet1 = 0;
		
		for (int i = 1; i <= 100; i++)
		{
			
			int x = (i - 1) % 10;
			
			int y = (i - 1) / 10;
			
			
			if (i == location)
			{
				cet++;
				drawImg(50 + x * 20, 50 + y * 20, &pink);
			}
			else if (i == a[cet])
			{
				cet++;
			}         
			else if (i % 10 == 5 || i % 10 == 6)
			{
				drawImg(50 + x * 20, 50 + y * 20, &green);
			}
			else if (i == location1)
			{
				cet1++;
				drawImg(50 + x * 20, 50 + y * 20, &pink);
			}
			else if (i == b[cet1])
			{
				cet1++;
			}
			else
			{
				drawImg(50 + x * 20, 50 + y * 20, &white);
			}
			
			
			if (i == 27 || i == 42 || i == 50 || i == 74) //炸弹
			{              
				drawImg(50 + x * 20, 50 + y * 20, &bomb);                            
			}
			
			if (i == 94 || i == 99)//通道
				drawImg(50 + x * 20, 50 + y * 20, &exit);
			
		}
		
		
		
		int onclick = _getch();
		
		cleardevice();
		
		int m = -1;
		
		int* m0 = &m;//赋给指针
		
		int p = -1;
		
		int* p0 = &p;
		
		movement(m0, onclick, location); 
		movement(p0, onclick, location1);
		
		
		for (int i = 0; i < num; i++) 
		{
			if (m == a[i]) 
			{
				location = m;
			}
		}
		
		for (int i = 0; i < num1; i++) 
		{
			if (p == b[i]) 
			{
				location1 = p;
			}
		}
		
		
		/*炸弹结束游戏*/
		if (location == 42 || location == 74 || location1 == 27 || location1 == 50) 
		{
			
			//*isprime0 = 7;
			gameover();
			break;
		}
		
		
		if (onclick == 27) 
		{
			pause();
			break;
		}
		
		if (location == a[num - 1]&& location1 == b[num1- 1] ) 
		{   
			
			settlement();
			break;
		}
		
	}
	
}

void Gamelobby()
{
	
	int choose = 0;
	int* choose0 = &choose;//用于控制箭头及选项
	int onclick;
	
	cleardevice();
	
	IMAGE yellow;
	
	loadimage(&yellow, "res/yellow.png");//边框
	
	
	
	while (1) 
	{
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		outtextxy(110, 100, ("开始游戏"));
		outtextxy(110, 120, ("游戏规则"));
		outtextxy(110, 140, ("游戏排行"));
		outtextxy(110, 160, ("开发人员"));
		outtextxy(110, 180, ("背景音乐"));
		outtextxy(110, 200, ("退出游戏"));
		
		outtextxy(80, 100 + choose * 20, ("--->"));
		
		
		onclick = _getch();
		
		cleardevice();
		
		updown(choose0, onclick, 6);//用于页面选择的函数
		
		if (choose == 0 && onclick == 13) 
		{
			isprime = 1;
			break;
		}
		
		else if (choose == 1 && onclick == 13) 
		{
			gamerules();
			break;
		}
		
		else if (choose == 2 && onclick == 13) 
		{
			rankings();
			break;
		}
		
		
		else if (choose == 3 && onclick == 13) 
		{
			developers();
			break;
		}
		
		else if (onclick == 27 || (choose == 5 && onclick == 13)) 
		{
			isprime = 7;
			break;
		}
		if (choose == 4 && onclick == 13)
		{
			music();
		}
		
	}
	
}

void updown(int* choose0, int onclick, int index)//选择，键盘事件，层数
{
	
	switch (onclick)
	{
	case 119:
	case 87:
		case 72:*choose0 -= 1; break;
		
	case 115:
	case 83:
		case 80:*choose0 += 1; break;
		
		default:break;
	}
	
	if (*choose0 < 0)//用于箭头到达最下面时，直接向上返回
		*choose0 = *choose0 +index;
	else
		*choose0 = *choose0%index;
	
}


void settlement() //游戏通过时出现的页面
{
	int choose = 0;
	int* choose0 = &choose;
	
	
	IMAGE yellow;
	
	loadimage(&yellow, "res/yellow.png");
	
	cleardevice();
	
	while (1) 
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		settextcolor(RED);
		
		outtextxy(110, 60, ("恭喜过关"));
		
		settextcolor(WHITE);
		
		
		outtextxy(110, 100, ("返回大厅"));
		outtextxy(110, 120, ("选择关卡"));
		outtextxy(110, 140, ("重新开始"));
		
		
		outtextxy(80, 100 + choose * 20, ("--->"));
		
		
		int onclick = _getch();
		
		updown(choose0, onclick, 3);
		
		
		cleardevice();
		
		if (choose == 0 && onclick == 13) //返回大厅页面
		{
			isprime = 0;
			break;
		}
		
		else if (choose == 1 && onclick == 13) //选择关卡
		{
			isprime = 1;
			break;
		}
		
		
		else if (choose == 2 && onclick == 13) //重新开始
		{           
			break;
		}
		
		
		
		
		
	}
	
}

void switchover() //选择关卡函数
{
	int choose = 0;
	int* choose0 = &choose;
	
	
	IMAGE yellow;
	
	loadimage(&yellow, "res/yellow.png");//边框
	
	while (1) 
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		
		outtextxy(110, 100, ("关卡一"));
		outtextxy(110, 120, ("关卡二"));
		outtextxy(110, 140, ("关卡三"));
		outtextxy(110, 160, ("关卡四"));
		outtextxy(110, 180, ("竞速关"));
		
		
		
		outtextxy(80, 100 + choose * 20, ("--->"));
		
		
		int onclick = _getch();
		
		
		updown(choose0, onclick, 5);//五层
		
		
		cleardevice();
		
		if (choose == 0 && onclick == 13) //1关
		{
			isprime = 2;
			break;
		}
		
		if (choose == 1 && onclick == 13)//2关
		{
			isprime = 3;
			break;
		}
		
		if (choose == 2 && onclick == 13)//3关
		{
			isprime = 4;
			break;
		}
		
		if (choose == 3 && onclick == 13)//4关
		{
			isprime = 5;
			break;
		}
		
		if (choose == 4 && onclick == 13) //5关
		{
			isprime = 6;
			break;
		}
		
		if (onclick == 27) //ESC返回
		{
			isprime= 0;
			break;
			
		}
		
	}
	
}

void pause() //游戏时暂停
{
	
	int choose = 0;
	int* choose0 = &choose;
	
	
	IMAGE yellow;
	
	loadimage(&yellow, _T("res/yellow.png"));
	
	while (1)
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					putimage(x, y, &yellow);
			}
		
		settextcolor(RED);
		outtextxy(110, 60, ("游戏暂停"));
		settextcolor(WHITE);
		
		outtextxy(110, 100, ("选择关卡"));
		outtextxy(110, 120, ("查看规则"));
		outtextxy(110, 140, ("返回大厅"));
		
		
		outtextxy(80, 100 + choose * 20, ("--->"));
		
		
		int onclick = _getch();//定义onclick函数用于下面的选择
		
		
		updown(choose0, onclick, 3);//3代表层数
		
		
		cleardevice();
		
		if (choose == 0 && onclick == 13) //选择关卡
		{
			isprime = 1;
			break;
		}
		
		if (choose == 1 && onclick == 13) //查看规则
		{
			gamerules();
			break;
		}
		
		if ((choose == 2 && onclick == 13)) //返回大厅
		{
			isprime = 0;
			break; 
		}
		
		if (onclick == 27)
		{
			break;
		}
		
		
		
		
	}
	
	
}

void gameover() 
{
	
	int choose = 0;
	int* choose0 = &choose;
	
	
	IMAGE yellow;
	
	loadimage(&yellow, _T("res/yellow.png"));
	
	outtextxy(110, 30, ("穿越迷宫"));
	outtextxy(30, 260, ("Esc : 退出"));
	outtextxy(180, 260, ("Enter : 确定 "));
	for (int x = 0; x <= 280; x += 20)
		for (int y = 0; y <= 280; y += 20)
		{
			if (x == 0 || y == 0 || x == 280 || y == 280)
				putimage(x, y, &yellow);
		}
	
	
	while (1) 
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					putimage(x, y, &yellow);
			}
		
		
		settextcolor(RED);//将以下文字定义为红色
		outtextxy(105, 60, ("Game Over"));
		settextcolor(WHITE);//将以下文字定义为白色
		outtextxy(110, 100, ("重新开始"));
		outtextxy(110, 120, ("查看规则"));
		outtextxy(110, 140, ("返回大厅"));
		
		
		outtextxy(80, 100 + choose * 20, ("--->"));
		
		
		int onclick = _getch();
		
		
		updown(choose0, onclick, 3);//3代表层数
		
		
		cleardevice();
		
		if (choose == 0 && onclick == 13)
		{
			
			break;
			
		}
		
		if (choose == 1 && onclick == 13) 
		{
			gamerules();
			//break;
		}
		
		if ((choose == 2 && onclick == 13)) 
		{
			isprime = 0;
			break;
			
		}
		
		
		
		
	}
	
	
	
	
}

void fourth()
{
	
	cleardevice();
	int a[] = { 1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,38,39,
		40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,71,72,73,74,75,76,77,
		78,79,80,81,82,83,85,86,89,90,91,92,93,94,95,96,97,98,99,100 };//包含炸弹的通道
	
	int c[] = { 2,14,19,21,23,27,31,36,38,50,52,53,55,58,62,64,66,67,86,89,92,95 };//炸弹
	int num = sizeof(a) / sizeof(a[0]);
	
	int num2 = sizeof(c) / sizeof(c[0]);
	int location = a[0];
	int location1 = a[7];
	
	IMAGE yellow, white, pink, green, bomb, exit ,rode;
	
	loadimage(&white, "res/white.png");
	loadimage(&pink, "res/pink.png");
	loadimage(&yellow, "res/yellow.png");
	loadimage(&green, ("res/green.png"));
	loadimage(&bomb, ("res/bomb.png"));
	loadimage(&exit, ("res/exit.png"));
	loadimage(&rode, ("res/rode.png"));
	
	
	
	while (1) 
	{
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20) 
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		
		
		
		int cet = 0, cet1 = 0;
		for (int i = 1; i <= 100; i++)
		{
			
			int x = (i - 1) % 10;
			
			int y = (i - 1) / 10;
			
			
			if (i == location||i==location1)
			{
				cet++;
				drawImg(50 + x * 20, 50 + y * 20, &pink);
				
			}
			else if (i == a[cet])
			{   
				drawImg(50 + x * 20, 50 + y * 20, &rode);
				cet++;
			}
			
			else
				drawImg(50 + x * 20, 50 + y * 20, &white);
			
			
			if (i == c[cet1]) 
			{
				cet1++;
				drawImg(50 + x * 20, 50 + y * 20, &bomb);
				//putimage(50 + x * 20, 50 + y * 20, &red1);
				//putimage(50 + x * 20, 50 + y * 20, &red);
				
			}
			
			if (i == 63 || i == 97)
			{
				drawImg(50 + x * 20, 50 + y * 20, &exit);
			}
			
			
		}
		
		
		
		int onclick = _getch();
		
		cleardevice();
		
		int m = -1;
		
		int* m0 = &m;
		
		int p = -1;
		
		int* p0 = &p;
		
		
		
		/*键盘事件*/
		
		movement(m0, onclick, location); //两个粉块
		movement(p0, onclick, location1);
		
		
		for (int i = 0; i < num; i++) //分别赋位
		{
			if (m == a[i] && m != location1)
			{
				location = m;
			}
		}
		
		for (int i = 0; i < num; i++) 
		{
			if (p == a[i] && p != location) 
			{
				location1 = p;
			}
		}
		
		
		bool isprime0 = false;
		for (int i = 0; i < num2; i++) 
		{
			if (location == c[i] || location1 == c[i])
			{
				isprime0 = true;//碰到炸弹
			}     
		}
		
		if (isprime0)
		{
			
			gameover();
			break;
		}
		
		if (onclick == 27) 
		{
			pause();
			break;
		}
		
		if ( (location == 63 && location1 == 97) || (location == 97 && location1 == 63) )
		{
			
			settlement();//过关
			break;
		}
		
		
	}
	
	
	
}

void fifth()
{
	
	cleardevice();//清屏
	
	int a[] = { 1,2,3,4,5,10,11,13,15,16,17,19,20,21,23,24,27,28,29,31,32,34,37,38,42,44,45,46,47,48,49,
		52,53,54,56,59,60,63,65,66,67,70,71,74,75,77,78,80,81,83,84,85,88,89,90,91,92,93,95,96 };//通道
	
	int b[] = { 3,16,20,31,38,46,67,71,80,83,96 };//星星
	
	int num = sizeof(a) / sizeof(a[0]);
	int num1 = sizeof(b) / sizeof(b[0]);
	int location = a[0];
	long long  time0 = time(0);//将此时的时间常量赋给变量
	
	IMAGE yellow, white, pink, star;
	
	loadimage(&white, "res/white.png");
	loadimage(&pink, "res/pink.png");
	loadimage(&yellow, "res/yellow.png");
	loadimage(&star, ("res/star.png"));
	
	while (1)
	{
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定"));
		for (int x = 0; x <= 280; x += 20)
		{
			for (int y = 0; y <= 280; y += 20)
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
				{
					drawImg(x, y, &yellow);
				}
			}
		}
		
		
		
		
		int cet = 0;
		for (int i = 1; i <= 100; i++)
		{
			int x = (i - 1) % 10;
			int y = (i - 1) / 10;
			
			if (i == location)
			{
				cet++;
				putimage(50 + x * 20, 50 + y * 20, &pink);
			}
			else if (i == a[cet])
			{
				cet++;
			}
			else
			{
				putimage(50 + x * 20, 50 + y * 20, &white);
			}
			
			for (int j = 0; j < num1; j++)
			{
				if (i == b[j])
				{
					drawImg(50 + 20 * x, 50 + 20 * y, &star);
				}
			}
			
		}
		
		int onclick = _getch();
		cleardevice();
		int m = -1;
		int* m0 = &m;
		
		
		movement(m0, onclick, location);
		
		for (int i = 0; i < num; i++)
		{
			if (m == a[i])
			{
				location = m;
			}
		}
		
		for (int k = 0; k < num1; k++) 
		{
			if (location == b[k])
				
			{
				b[k] = 0;//粉块走至星星处，将星星数组此处的值赋为零
			}
		}
		
		bool game = true;
		for (int l = 0; l < num1; l++)
		{
			if (b[l] != 0)
				game = false;
		}
		
		if (game)//星星全部消失
		{
			long long time1 = time(0) - time0;//用此时的时间减去刚才的时间
			ranking(time1);//将时间写入txt文件 
			cleardevice();        
			settlement();//过关
			break;
		}
		
		if (onclick == 27)
		{
			pause();
			break;
		}
		
	}
	
}

void developers()
{
	IMAGE yellow;
	
	loadimage(&yellow, "res/yellow.png");
	
	while (1) 
	{
		
		
		//基本框架
		outtextxy(120, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20)
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		
		
		
		settextcolor(YELLOW);
		outtextxy(115, 100, ("吕"));
		outtextxy(115, 120, ("孙"));
		settextcolor(BLUE);
		outtextxy(135, 100, ("博"));
		outtextxy(135, 120, ("刚"));
		settextcolor(GREEN);
		outtextxy(155, 100, ("宇"));
		outtextxy(155, 120, ("强"));
		settextcolor(WHITE);
		outtextxy(100, 70, ("-----------------------"));
		outtextxy(100, 150, ("-----------------------"));
		
		outtextxy(100, 70, ("|"));
		outtextxy(100, 90, ("|"));
		outtextxy(100, 110, ("|"));
		outtextxy(100, 130, ("|"));
		outtextxy(100, 150, ("|"));
		
		outtextxy(190, 70, ("|"));
		outtextxy(190, 90, ("|"));
		outtextxy(190, 110, ("|"));
		outtextxy(190, 130, ("|"));
		outtextxy(190, 150, ("|"));
		
		int onclick = _getch();
		
		cleardevice();
		
		if (onclick == 27)//ESC返回
		{
			break;
		}
	}
}

void gamerules()
{
	
	
	int choose = 0;
	int* choose0 = &choose;
	
	
	IMAGE yellow, white, pink, green, bomb, exit, rode, star;
	
	loadimage(&white, "res/white.png");
	loadimage(&pink, "res/pink.png");
	loadimage(&yellow, "res/yellow.png");
	loadimage(&green, ("res/green.png"));
	loadimage(&bomb, ("res/bomb.png"));
	loadimage(&exit, ("res/exit.png"));
	loadimage(&rode, ("res/rode.png"));
	loadimage(&star, ("res/star.png"));
	
	
	
	
	while (1) 
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20)
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		
		
		settextcolor(WHITE);
		
		
		
		drawImg(105, 80, &pink);
		drawImg(105, 100, &bomb);
		drawImg(105, 120, &exit);
		drawImg(105, 140, &star);
		drawImg(105, 160, &yellow);
		drawImg(105, 180, &green);
		drawImg(105, 200, &rode);
		drawImg(105, 220, &white);
		
		outtextxy(130, 80, ("：玩家"));
		outtextxy(130, 100, ("：炸弹"));
		outtextxy(130, 120, ("：出口"));
		outtextxy(130, 140, ("：星星"));
		outtextxy(130, 160, ("：边框"));
		outtextxy(130, 180, ("：中框"));
		outtextxy(130, 200, ("：背影"));
		outtextxy(130, 220, ("：路障"));
		int onclick = _getch();
		
		cleardevice();
		
		if (onclick == 27)
		{
			break;
		}
		
	}
	
}

void ranking(long long  time) 
{
	
	
	IMAGE yellow;
	
	loadimage(&yellow, "res/yellow.png");
	
	int c = 0;
	string name = "\0";
	int cet = 0;
	
	TCHAR second[5];
	_stprintf_s(second, "%lld", time);		// 高版本 VC 推荐使用 _stprintf_s 函数
	
	
	while (1) 
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20)
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}
		
		settextcolor(RED);
		outtextxy(110, 60, ("恭喜过关"));
		
		outtextxy(105, 100, ("用时：   秒"));
		
		outtextxy(147, 100, second);
		
		settextcolor(WHITE);
		
		
		outtextxy(95, 140, ("请输入玩家名"));
		
		if(!cet)
			fillrectangle(85, 175, 197, 200);
		
		
		if (c == 13) 
		{
			fstream inout;
			inout.open("res/time.txt", ios::out | ios::app);
			inout << name << " " << time << " ";
			inout.close();
			break;
		}
		
		c = _getch();
		
		
		if (c == 8 && cet == 0)
			;
		else if (c == 8)
			name.erase(--cet, 1);//一次删除一个字节
		
		else if (c == 27)
			break;
		
		else if (c != 13) 
		{ 
			name += c;
			cet++;//确定字节数，以确定输入时准确删除
		}
		cleardevice();
		
		
		cleardevice();
		
		fillrectangle(85, 175, 197, 200);
		
		outtextxy(120, 180, name.c_str());           
		
	}
	
}

void rankings() 
{
	IMAGE yellow;
	
	loadimage(&yellow, "res/yellow.png");
	
	fstream inout;
	inout.open("res/time.txt", ios::in);
	Player player[100];
	int cet = 0;   
	string name0;
	int time0;
	
	while (inout >> name0) 
	{     
		inout >> time0;
		player[cet] = { name0,time0 };//导出txt中的玩家名及时间,赋值给结构体数组
		cet++;
	}
	
	inout.close();//关闭文件
	
	
	for (int i = 1; i < cet; i++)//比较排序
	{
		for (int j = 0; j < i && j < 10; j++)
		{
			if (player[i].time < player[j].time)
				swap(player[i], player[j]);
		}
	}
	
	while (1) 
	{
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20)
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					drawImg(x, y, &yellow);
			}     
		
		outtextxy(80, 50, ("玩家"));
		outtextxy(170, 50, ("用时"));
		
		settextcolor(RED);
		
		for (int i = 0; i < 10 && i<cet; i++) 
		{
			
			
			char second[5];
			_stprintf_s(second, "%d", player[i].time);
			
			outtextxy(80, 70+i*19, player[i].name.c_str());
			
			outtextxy(175, 70+i*19, second);
			
			outtextxy(195, 70 + i * 19, "s");
			
			if(i>=2)
				settextcolor(WHITE);
		}
		
		settextcolor(WHITE);
		
		int onclick = _getch();
		
		cleardevice();
		
		if (onclick == 27)
		{
			break;
		}
		
		
	}
}

void music()
{
	int choose = 0;
	int* choose0 = &choose;
	
	
	IMAGE yellow;
	
	loadimage(&yellow, _T("res/yellow.png"));
	
	while (1)
	{
		
		
		//基本框架
		outtextxy(110, 30, ("穿越迷宫"));
		outtextxy(30, 260, ("Esc : 退出"));
		outtextxy(180, 260, ("Enter : 确定 "));
		for (int x = 0; x <= 280; x += 20)
			for (int y = 0; y <= 280; y += 20)
			{
				if (x == 0 || y == 0 || x == 280 || y == 280)
					putimage(x, y, &yellow);
			}
		
		
		settextcolor(WHITE);
		
		outtextxy(110, 100, ("关闭声音"));
		outtextxy(110, 120, ("开启声音"));
		outtextxy(110, 140, ("返回大厅"));
		
		
		outtextxy(80, 100 + choose * 20, ("--->"));
		
		
		int onclick = _getch();//定义onclick函数用于下面的选择
		
		
		updown(choose0, onclick, 3);//3代表层数
		
		
		cleardevice();
		
		if (choose == 0 && onclick == 13) 
		{
			mciSendString("close music ", 0, 0, 0);
			
		}
		
		else if (choose == 1 && onclick == 13) 
		{
			mciSendString("open ./res/music1.mp3 alias music", 0, 0, 0);
			
			mciSendString("play music ", 0, 0, 0);
			
			
		}
		
		else if ((choose == 2 && onclick == 13))
		{
			isprime = 0;
			break;
		}
		
		if (onclick == 27)
		{
			break;
		}
		
		
		
		
	}
	
	
}






